<meta charset="utf-8">
(#) Button should be borderless

!!! WARNING: Button should be borderless
   This is a warning.

Id
:   `ButtonStyle`
Summary
:   Button should be borderless
Severity
:   Warning
Category
:   Usability
Platform
:   Android
Vendor
:   Android Open Source Project
Feedback
:   https://issuetracker.google.com/issues/new?component=192708
Since
:   Initial
Affects
:   Resource files
Editing
:   This check runs on the fly in the IDE editor
See
:   https://d.android.com/r/studio-ui/designer/material/dialogs
Implementation
:   [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ButtonDetector.java)
Tests
:   [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ButtonDetectorTest.java)
Copyright Year
:   2012

Button bars typically use a borderless style for the buttons. Set the
`style="?android:attr/buttonBarButtonStyle"` attribute on each of the
buttons, and set `style="?android:attr/buttonBarStyle"` on the parent
layout.

!!! Tip
   This lint check has an associated quickfix available in the IDE.

(##) Example

Here is an example of lint warnings produced by this check:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text
res/layout/buttonbar.xml:12:Warning: Buttons in button bars should be
borderless; use style="?android:attr/buttonBarButtonStyle" (and
?android:attr/buttonBarStyle on the parent) [ButtonStyle]
    &lt;Button
     ------
res/layout/buttonbar.xml:17:Warning: Buttons in button bars should be
borderless; use style="?android:attr/buttonBarButtonStyle" (and
?android:attr/buttonBarStyle on the parent) [ButtonStyle]
    &lt;Button
     ------
res/layout/buttonbar.xml:28:Warning: Buttons in button bars should be
borderless; use style="?android:attr/buttonBarButtonStyle" (and
?android:attr/buttonBarStyle on the parent) [ButtonStyle]
    &lt;Button
     ------
res/layout/buttonbar.xml:33:Warning: Buttons in button bars should be
borderless; use style="?android:attr/buttonBarButtonStyle" (and
?android:attr/buttonBarStyle on the parent) [ButtonStyle]
    &lt;Button
     ------
res/layout/buttonbar.xml:44:Warning: Buttons in button bars should be
borderless; use style="?android:attr/buttonBarButtonStyle" (and
?android:attr/buttonBarStyle on the parent) [ButtonStyle]
    &lt;Button
     ------
res/layout/buttonbar.xml:49:Warning: Buttons in button bars should be
borderless; use style="?android:attr/buttonBarButtonStyle" (and
?android:attr/buttonBarStyle on the parent) [ButtonStyle]
    &lt;Button
     ------
res/layout/buttonbar.xml:60:Warning: Buttons in button bars should be
borderless; use style="?android:attr/buttonBarButtonStyle" (and
?android:attr/buttonBarStyle on the parent) [ButtonStyle]
    &lt;Button
     ------
res/layout/buttonbar.xml:65:Warning: Buttons in button bars should be
borderless; use style="?android:attr/buttonBarButtonStyle" (and
?android:attr/buttonBarStyle on the parent) [ButtonStyle]
    &lt;Button
     ------
res/layout/buttonbar.xml:76:Warning: Buttons in button bars should be
borderless; use style="?android:attr/buttonBarButtonStyle" (and
?android:attr/buttonBarStyle on the parent) [ButtonStyle]
    &lt;Button
     ------
res/layout/buttonbar.xml:81:Warning: Buttons in button bars should be
borderless; use style="?android:attr/buttonBarButtonStyle" (and
?android:attr/buttonBarStyle on the parent) [ButtonStyle]
    &lt;Button
     ------
res/layout/buttonbar.xml:92:Warning: Buttons in button bars should be
borderless; use style="?android:attr/buttonBarButtonStyle" (and
?android:attr/buttonBarStyle on the parent) [ButtonStyle]
    &lt;Button
     ------
res/layout/buttonbar.xml:97:Warning: Buttons in button bars should be
borderless; use style="?android:attr/buttonBarButtonStyle" (and
?android:attr/buttonBarStyle on the parent) [ButtonStyle]
    &lt;Button
     ------
res/layout/buttonbar.xml:108:Warning: Buttons in button bars should be
borderless; use style="?android:attr/buttonBarButtonStyle" (and
?android:attr/buttonBarStyle on the parent) [ButtonStyle]
    &lt;Button
     ------
res/layout/buttonbar.xml:113:Warning: Buttons in button bars should be
borderless; use style="?android:attr/buttonBarButtonStyle" (and
?android:attr/buttonBarStyle on the parent) [ButtonStyle]
    &lt;Button
     ------
res/layout/buttonbar.xml:124:Warning: Buttons in button bars should be
borderless; use style="?android:attr/buttonBarButtonStyle" (and
?android:attr/buttonBarStyle on the parent) [ButtonStyle]
    &lt;Button
     ------
res/layout/buttonbar.xml:129:Warning: Buttons in button bars should be
borderless; use style="?android:attr/buttonBarButtonStyle" (and
?android:attr/buttonBarStyle on the parent) [ButtonStyle]
    &lt;Button
     ------
res/layout/buttonbar.xml:140:Warning: Buttons in button bars should be
borderless; use style="?android:attr/buttonBarButtonStyle" (and
?android:attr/buttonBarStyle on the parent) [ButtonStyle]
    &lt;Button
     ------
res/layout/buttonbar.xml:145:Warning: Buttons in button bars should be
borderless; use style="?android:attr/buttonBarButtonStyle" (and
?android:attr/buttonBarStyle on the parent) [ButtonStyle]
    &lt;Button
     ------
res/layout/buttonbar.xml:156:Warning: Buttons in button bars should be
borderless; use style="?android:attr/buttonBarButtonStyle" (and
?android:attr/buttonBarStyle on the parent) [ButtonStyle]
    &lt;Button
     ------
res/layout/buttonbar.xml:161:Warning: Buttons in button bars should be
borderless; use style="?android:attr/buttonBarButtonStyle" (and
?android:attr/buttonBarStyle on the parent) [ButtonStyle]
    &lt;Button
     ------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Here are the relevant source files:

`res/layout/buttonbar.xml`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" &gt;

    &lt;!-- Hardcoded strings, wrong order --&gt;
    &lt;LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" &gt;

        &lt;Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="OK" /&gt;

        &lt;Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Cancel" /&gt;
    &lt;/LinearLayout&gt;

    &lt;!-- Hardcoded strings, right order --&gt;
    &lt;LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" &gt;

        &lt;Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Cancel" /&gt;

        &lt;Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="OK" /&gt;
    &lt;/LinearLayout&gt;

    &lt;!-- @android:string resources, wrong order --&gt;
    &lt;LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" &gt;

        &lt;Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@android:string/ok" /&gt;

        &lt;Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@android:string/cancel" /&gt;
    &lt;/LinearLayout&gt;

    &lt;!-- @android:string resources, right order --&gt;
    &lt;LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" &gt;

        &lt;Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@android:string/cancel" /&gt;

        &lt;Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@android:string/ok" /&gt;
    &lt;/LinearLayout&gt;

    &lt;!-- @string/ok/cancel resources, right order --&gt;
    &lt;LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" &gt;

        &lt;Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/cancel" /&gt;

        &lt;Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/ok" /&gt;
    &lt;/LinearLayout&gt;

    &lt;!-- @string/ok/cancel resources, wrong order --&gt;
    &lt;LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" &gt;

        &lt;Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/ok" /&gt;

        &lt;Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/cancel" /&gt;
    &lt;/LinearLayout&gt;

    &lt;!-- Random name resources, right order --&gt;
    &lt;LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" &gt;

        &lt;Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/giveup" /&gt;

        &lt;Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/resume" /&gt;
    &lt;/LinearLayout&gt;

    &lt;!-- Random name resources, wrong order --&gt;
    &lt;LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" &gt;

        &lt;Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/resume" /&gt;

        &lt;Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/giveup" /&gt;
    &lt;/LinearLayout&gt;

    &lt;!-- Random name resources with varying case, wrong order --&gt;
    &lt;LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" &gt;

        &lt;Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/resume2" /&gt;

        &lt;Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/giveup2" /&gt;
    &lt;/LinearLayout&gt;

    &lt;!-- Resources with only one of OK and Cancel, wrong order --&gt;
    &lt;LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" &gt;

        &lt;Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/ok" /&gt;

        &lt;Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/abort" /&gt;
    &lt;/LinearLayout&gt;

    &lt;!-- Resources with only one of OK and Cancel, wrong order --&gt;
    &lt;LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" &gt;

        &lt;Button
            android:layout_width="wrap_content" android:background="?android:attr/selectableItemBackground"
            android:layout_height="wrap_content"
            android:text="@string/send" /&gt;

        &lt;Button
            android:layout_width="wrap_content" android:background="?android:attr/selectableItemBackground"
            android:layout_height="wrap_content"
            android:text="@string/cancel" /&gt;
    &lt;/LinearLayout&gt;

    &lt;Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/goback" /&gt;

&lt;/LinearLayout&gt;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

`res/layout/buttonbar2.xml`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" &gt;

    &lt;ProgressBar
        android:id="@+id/loading_progress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginBottom="60dip"
        android:layout_marginLeft="40dip"
        android:layout_marginTop="40dip"
        android:max="10000" /&gt;

    &lt;TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignWithParentIfMissing="true"
        android:layout_marginBottom="60dip"
        android:layout_marginLeft="40dip"
        android:layout_marginTop="40dip"
        android:layout_toRightOf="@id/loading_progress"
        android:ellipsize="end"
        android:maxLines="3"
        android:paddingRight="120dip"
        android:text="@string/creating_instant_mix"
        android:textAppearance="?android:attr/textAppearanceMedium" /&gt;

    &lt;Button
        android:id="@+id/cancel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignRight="@id/text"
        android:layout_below="@id/text"
        android:background="@null"
        android:text="@string/cancel" /&gt;

    &lt;ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@id/cancel"
        android:layout_alignLeft="@id/cancel"
        android:layout_alignRight="@id/cancel"
        android:scaleType="fitXY"
        android:src="@drawable/menu_list_divider" /&gt;

&lt;/RelativeLayout&gt;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

`res/layout/buttonbar3.xml`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" &gt;

    &lt;TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="@string/weekpicker_title"
        android:textAppearance="?android:attr/textAppearanceMedium" /&gt;

    &lt;RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ffffff"
        android:padding="6dip" &gt;

        &lt;Button
            android:id="@+id/set"
            android:layout_width="120dip"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:text="@string/weekpicker_set" /&gt;

        &lt;Button
            android:id="@+id/cancel"
            android:layout_width="120dip"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:text="@string/cancel" /&gt;
    &lt;/RelativeLayout&gt;

&lt;/LinearLayout&gt;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

`res/values/buttonbar-values.xml`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;resources&gt;

    &lt;string name="button"&gt; Button &lt;/string&gt;
    &lt;string name="ok"&gt; OK &lt;/string&gt;
    &lt;string name="cancel"&gt; Cancel &lt;/string&gt;
    &lt;string name="resume"&gt; OK &lt;/string&gt;
    &lt;string name="giveup"&gt; Cancel &lt;/string&gt;
    &lt;string name="resume2"&gt; Ok &lt;/string&gt;
    &lt;string name="giveup2"&gt;"CANCEL"&lt;/string&gt;
    &lt;string name="send"&gt; Send &lt;/string&gt;
    &lt;string name="abort"&gt;Abort&lt;/string&gt;
    &lt;string name="goback"&gt;'Back'&lt;/string&gt;

&lt;/resources&gt;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You can also visit the
[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ButtonDetectorTest.java)
for the unit tests for this check to see additional scenarios.

The above example was automatically extracted from the first unit test
found for this lint check, `ButtonDetector.testButtonStyle`.
To report a problem with this extracted sample, visit
https://issuetracker.google.com/issues/new?component=192708.

(##) Suppressing

You can suppress false positives using one of the following mechanisms:

* Adding the suppression attribute `tools:ignore="ButtonStyle"` on the
  problematic XML element (or one of its enclosing elements). You may
  also need to add the following namespace declaration on the root
  element in the XML file if it's not already there:
  `xmlns:tools="http://schemas.android.com/tools"`.

  ```xml
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;resources xmlns:tools="http://schemas.android.com/tools"&gt;
      ...
      &lt;Button tools:ignore="ButtonStyle" .../&gt;
    ...
  &lt;/resources&gt;
  ```

* Using a special `lint.xml` file in the source tree which turns off
  the check in that folder and any sub folder. A simple file might look
  like this:
  ```xml
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;lint&gt;
      &lt;issue id="ButtonStyle" severity="ignore" /&gt;
  &lt;/lint&gt;
  ```
  Instead of `ignore` you can also change the severity here, for
  example from `error` to `warning`. You can find additional
  documentation on how to filter issues by path, regular expression and
  so on
  [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html).

* In Gradle projects, using the DSL syntax to configure lint. For
  example, you can use something like
  ```gradle
  lintOptions {
      disable 'ButtonStyle'
  }
  ```
  In Android projects this should be nested inside an `android { }`
  block.

* For manual invocations of `lint`, using the `--ignore` flag:
  ```
  $ lint --ignore ButtonStyle ...`
  ```

* Last, but not least, using baselines, as discussed
  [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html).

<!-- Markdeep: --><style class="fallback">body{visibility:hidden;white-space:pre;font-family:monospace}</style><script src="markdeep.min.js" charset="utf-8"></script><script src="https://morgan3d.github.io/markdeep/latest/markdeep.min.js" charset="utf-8"></script><script>window.alreadyProcessedMarkdeep||(document.body.style.visibility="visible")</script>